public class RemoveDuplicates {

    public static void main(String[] args) {
        RemoveDuplicates removeDuplicates = new RemoveDuplicates();
        int[] nums = {0,0,1,1,1,1,2,3,3};
        System.out.println(removeDuplicates.removeDuplicates(nums));
    }

    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        if (n == 1 || n == 0) return n;
        int ans = 1;
        for (int i = 1; i < n;) {
            if (nums[i] == nums[i - 1]) {
                process(nums, i);
                n--;
            } else {
                ans++;
                i++;
            }
        }
        return ans;
    }

    public void process(int[] nums, int n) {
        for (int i = n; i < nums.length; i++) {
            nums[i - 1] = nums[i];
        }
    }

    public int removeDuplicates1(int[] nums) {
        int n = nums.length;
        if (n == 1 || n == 0) return n;
        int slow = 1;
        int fast = 1;
        while (fast < n) {
            if (nums[fast] != nums[fast - 1]) {
                nums[slow] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;
    }
}
